package com.mall.controller;

import com.mall.common.domain.R;
import com.mall.common.exception.BizIllegalException;
import com.mall.common.utils.UserContext;
import com.mall.domain.dto.PayApplyDTO;
import com.mall.domain.dto.PayOrderFormDTO;
import com.mall.domain.response.Response;
import com.mall.enums.PayType;
import com.mall.service.PayOrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("pay-orders")
@RequiredArgsConstructor
public class PayController {
    
    private final PayOrderService payOrderService;

    /**
     * 生成支付单
     * @param payApplyDTO
     * @return
     */
    @PostMapping
    public String applyPayOrder(@RequestBody PayApplyDTO payApplyDTO){
        if (!PayType.BALANCE.equalsValue(payApplyDTO.getPayType())){
                throw new BizIllegalException("目前只支持余额支付");
        }
        return payOrderService.applyPayOrder(payApplyDTO);
    }

    /**
     * 用户余额支付
     * @param id
     * @param payOrderFormDTO
     */
    @PostMapping("/{id}")
    public void tryPayOrderByBalance(@PathVariable("id")Long id, @RequestBody PayOrderFormDTO payOrderFormDTO){
        payOrderFormDTO.setId(id);
        payOrderService.tryPayOrderByBalance(payOrderFormDTO);
    }


}
